package com.ambulance.project.biz.controller.agora;


import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.domain.AjaxResultData;
import com.ambulance.project.biz.service.WebCustomerService;
import com.ambulance.utils.OkHttp3Util;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 人员信息 前端控制器
 * </p>
 *
 * @author zr
 * @since 2020-04-21
 */

@Api(tags = {"声网-通用接口"})
@RestController
@RequestMapping(value = "/agora/v1/")
public class AgoraCommonController {


    private static Logger logger = LoggerFactory.getLogger(AgoraCommonController.class);

    @Value(("${agora.appId}"))
    private String appid;

    @Value(("${agora.publicChannel}"))
    private String publicChannel;

    @Value(("${agora.API.baseurl}"))
    private String baseUrl;


    @Autowired
    private WebCustomerService webCustomerService;
    @Autowired
    private OkHttp3Util okHttp3Util;

    @GetMapping(value = "/appid")
    @ResponseBody
    @ApiOperation(value = "声网AppID", notes = "AppID", produces = "application/json")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")

    })
    public AjaxResult appid(
    ) {
        return AjaxResult.success(appid);
    }

    @GetMapping(value = "/publicChannel")
    @ResponseBody
    @ApiOperation(value = "获取声网公共频道", notes = "channel", produces = "application/json")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")

    })
    public AjaxResult publicChannel(
    ) {
        return AjaxResult.success(publicChannel);
    }

    @GetMapping(value = "/token")
    @ResponseBody
    @ApiOperation(value = "获取声网token", notes = "获取声网token", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channel", value = "通道", required = true, paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "account", value = "用户账号名,声网根据用户账户名来生成对应的token", required = true, paramType = "form", dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")

    })
    @Deprecated
    public AjaxResult getAgoraToken(
            @RequestParam(value = "channel", required = false, defaultValue = "public") String channel,
            @RequestParam(value = "account", required = false, defaultValue = "hello") String account
    ) {

        String agoraToken = webCustomerService.getAgoraToken(channel, account);

        return AjaxResult.success(agoraToken);
    }

}
